Ruby モジュール
#Ruby
include
モジュールのメソッドをインスタンスメソッドとして呼び出せる
prependでミックスインするとモジュールのメソッドが優先される
extend
モジュールのメソッドをクラスメソッドとして呼び出せる
確認
code:rb
Product.include?(Loggable) #=> true
Product.included_modules #=> Loggable, Kernel
Product.ancestors #=> Product, Loggable, Object, Kernel, BasicObject
code:rb
product = Product.new
product.class.include?(Loggable) #=> true
product.is_a?(Product) #=> true
product.is_a?(Loggable) #=> true
product.is_a?(Object) #=> true
code:rb
Hash.include?(Enumerable) #=> true
名前空間
呼び出し方:モジュール名::クラス名
モジュールはクラスインスタンス変数を持つことができる